<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="单号" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="承运商" prop="jcCarrierId">
        <el-input v-model="queryParams.jcCarrierId" placeholder="请输入承运商" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="承运类型" prop="carrierType">
        <el-select v-model="queryParams.carrierType" placeholder="请选择承运类型" clearable>
          <el-option v-for="dict in dict.type.Cytp" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="司机姓名" prop="driver">
        <el-input v-model="queryParams.driver" placeholder="请输入司机姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="司机电话" prop="driverIphone">
        <el-input v-model="queryParams.driverIphone" placeholder="请输入司机电话" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="车牌号" prop="vehicleHead">
        <el-input v-model="queryParams.vehicleHead" placeholder="请输入车牌号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="计划时间">
        <el-date-picker v-model="daterangeDateBilling" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="实际结束时间">
        <el-date-picker v-model="daterangePlanEndTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="实际出发时间">
        <el-date-picker v-model="daterangePlanStartTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['shipment:dispatch:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['shipment:dispatch:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['shipment:dispatch:remove']">删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['shipment:dispatch:export']">导出
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-s-check" size="mini" :disabled="single" @click="handleAbnormal"
          v-hasPermi="['shipment:dispatch:abnormal']">异常修改
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-right" size="mini" @click="handleStartExe"
          v-hasPermi="['shipment:dispatch:exe']">开始执行
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-right" size="mini" @click="handleEndExe"
          v-hasPermi="['shipment:dispatch:exe']">结束执行
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dispatchList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column label="组织网点" align="center" prop="dtMap.jcOrganizationIdDtLabel" />
      <el-table-column label="单号" align="center" prop="code" width="110" />
      <el-table-column label="计划时间" align="center" prop="dateBilling" width="180" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="dict.type.TPDZT" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="件数" align="center" prop="number" />
      <el-table-column label="体积" align="center" prop="volume" />
      <el-table-column label="重量" align="center" prop="weight" />
      <el-table-column label="提派信息" align="center" prop="toSendInfo" />
      <el-table-column label="承运类型" align="center" prop="carrierType">
        <template #default="scope">
          <dict-tag :options="dict.type.Cytp" :value="scope.row.carrierType" />
        </template>
      </el-table-column>
      <el-table-column label="承运商" align="center" prop="dtMap.jcCarrierIdDtLabel" width="140" />
      <el-table-column label="承运商是否超期" align="center" prop="isOverdueCarrier">
        <template #default="scope">
          <dict-tag :options="dict.type.CommIsNot" :value="scope.row.isOverdueCarrier" />
        </template>
      </el-table-column>
      <el-table-column label="司机姓名" align="center" prop="driver" width="140">
        <template #default="scope">
          <span v-if="scope.row.driver">{{ scope.row.driver }}</span>
          <span v-else>{{ scope.row.driverTemporary }}</span>
        </template>
      </el-table-column>
      <el-table-column label="司机电话" align="center" prop="driverIphone" width="110">
        <template #default="scope">
          <span v-if="scope.row.driverIphone">{{ scope.row.driverIphone }}</span>
          <span v-else>{{ scope.row.driverIphoneTemporary }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车牌号" align="center" prop="vehicleHead" width="100">
        <template #default="scope">
          <span v-if="scope.row.vehicleHead">{{ scope.row.vehicleHead }}</span>
          <span v-else>{{ scope.row.vehicleheadTemporary }}</span>
        </template>
      </el-table-column>
      <!-- 重泡比-->
      <el-table-column label="重泡比" align="center" prop="rebubbleRatio" />
      <!--        结算方式 -->
      <el-table-column label="结算方式" align="center" prop="accountType">
        <template #default="scope">
          <dict-tag :options="dict.type.Clearing" :value="scope.row.accountType" />
        </template>
      </el-table-column>
      <el-table-column label="实际出发点击时间" align="center" prop="planClickEndTime" width="180" />
      <el-table-column label="实际结束点击时间" align="center" prop="planClickStartTime" width="180" />
      <el-table-column label="实际结束时间" align="center" prop="planEndTime" width="180" />
      <el-table-column label="实际出发时间" align="center" prop="planStartTime" width="180" />
      <!--        是否有异常-->
      <el-table-column label="是否有异常" align="center" prop="isAbnormail">
        <template #default="scope">
          <dict-tag :options="dict.type.CommIsNot" :value="scope.row.isAbnormail" />
        </template>
      </el-table-column>
      <!--        创建人-->
      <el-table-column label="创建人" align="center" prop="createName" />
      <!--        创建时间-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="100" />
      <!--        修改人-->
      <el-table-column label="修改人" align="center" prop="modifyName" />
      <!--        修改时间-->
      <el-table-column label="修改时间" align="center" prop="modifyTime" width="180" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180" fixed="right">
        <template #default="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['shipment:dispatch:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['shipment:dispatch:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改提派单对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="单号" prop="code">
              <el-input v-model="form.code" placeholder="请输入单号" disabled="disabled" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计划时间" prop="dateBilling">
              <el-date-picker clearable v-model="form.dateBilling" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择计划时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!--          车型-->
          <el-col :span="8">
            <el-form-item label="车型" prop="jcVehicleId">
              <el-select clearable v-model="form.jcVehicleId" placeholder="请选择车型" @change="changeVehicle">
                <el-option v-for="vehicle in vehicleTypes" :key="vehicle.id" :label="vehicle.code"
                  :value="vehicle.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <!--          承运类型-->
          <el-col :span="8">
            <el-form-item label="承运类型" prop="carrierType">
              <el-select clearable v-model="form.carrierType" placeholder="请选择承运类型">
                <el-option v-for="dict in dict.type.Cytp" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)" />
              </el-select>
            </el-form-item>
          </el-col>
          <!--          承运商-->
          <el-col :span="8">
            <el-form-item label="承运商" prop="jcCarrierId">
              <el-select clearable v-model="form.jcCarrierId" placeholder="请选择承运商">
                <el-option v-for="carrier in carrierList" :key="carrier.id" :label="carrier.name" :value="carrier.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <!--          车牌号-->
          <el-col :span="8">
            <el-form-item label="车牌号" prop="vehicleHead">
              <el-select clearable v-model="form.vehicleHead" placeholder="请选择车牌号" @change="handleLicenseSelect">
                <el-option v-for="dict in licenseList" :key="dict.id" :label="dict.code" value-key="value"
                  :value="dict.code" />
              </el-select>
            </el-form-item>
          </el-col>
          <!--          司机-->
          <el-col :span="8">
            <el-form-item label="司机" prop="driver">
              <el-autocomplete v-model="form.driver" :fetch-suggestions="queryDriverSearch" placeholder="请输入司机名称进行搜索"
                @select="handleDriverSelect" />
            </el-form-item>
          </el-col>
          <!--          司机电话-->
          <el-col :span="8">
            <el-form-item label="司机电话" prop="driverIphone">
              <el-input v-model="form.driverIphone" placeholder="请输入司机电话" />
            </el-form-item>
          </el-col>
          <!--          结算方式-->
          <el-col :span="8">
            <el-form-item label="结算方式" prop="accountType">
              <el-select clearable v-model="form.accountType" placeholder="请选择结算方式">
                <el-option v-for="dict in dict.type.Clearing" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)" />
              </el-select>
            </el-form-item>
          </el-col>
          <!--          车费-->
          <el-col :span="8">
            <el-form-item label="车费" prop="cost1">
              <el-input-number v-model="form.cost1" placeholder="请输入车费" />
            </el-form-item>
          </el-col>
          <!--          上楼费-->
          <el-col :span="8">
            <el-form-item label="上楼费" prop="cost2">
              <el-input-number v-model="form.cost2" placeholder="请输入上楼费" />
            </el-form-item>
          </el-col>
          <!--          装卸费-->
          <el-col :span="8">
            <el-form-item label="装卸费" prop="cost3">
              <el-input-number v-model="form.cost3" placeholder="请输入装卸费" />
            </el-form-item>
          </el-col>
          <!--          其他费用-->
          <el-col :span="8">
            <el-form-item label="其他费用" prop="cost4">
              <el-input-number v-model="form.cost4" placeholder="请输入其他费用" />
            </el-form-item>
          </el-col>
          <!--          税率-->
          <el-col :span="24">
            <el-form-item label="税率" prop="rate">
              <el-radio-group v-model="form.rate">
                <el-radio v-for="dict in dict.type.TaxRate" :key="dict.value" :label="Number(dict.label)">{{ dict.label
                  }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <!--          税金-->
          <el-col :span="8">
            <el-form-item label="税金" prop="taxes">
              <el-input v-model="taxes" placeholder="请输入税金" readonly="readonly" />
            </el-form-item>
          </el-col>
          <!--          总车费-->
          <el-col :span="8">
            <el-form-item label="总车费" prop="cost">
              <el-input v-model="cost" placeholder="请输入总车费" readonly="readonly" />
            </el-form-item>
          </el-col>
          <!--          备注-->
          <el-col :span="24">
            <el-form-item label="备注" prop="description">
              <el-input v-model="form.description" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="!form.status || form.status === 1" type="primary" @click="submitForm">确 定</el-button>
        <el-button v-if="abnormal" type="primary" @click="handleSaveAbnormal">确定修改</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listDispatch,
  getDispatch,
  delDispatch,
  addDispatch,
  updateDispatch,
  startDispatch, dispatchSaveAbnormal
} from "@/api/dispatch/dispatch";
import { allListCarrier } from "@/api/vehicle/carrier";
import { allListVehicle } from "@/api/vehicle/vehicle";
import { searchVehicleExistList } from "@/api/vehicle/vehicleHead";
import { searchListDriver } from "@/api/vehicle/driver";

export default {
  name: "Dispatch",
  dicts: ['Clearing', 'Cytp', 'CommIsNot', 'TPDZT', 'TaxRate'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      codes: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      abnormal: false,
      // 总条数
      total: 0,
      // 提派单表格数据
      dispatchList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // $comment时间范围
      daterangeCreateTime: [],
      // $comment时间范围
      daterangeModifyTime: [],
      // $comment时间范围
      daterangeDateBilling: [],
      // $comment时间范围
      daterangePlanClickEndTime: [],
      // $comment时间范围
      daterangePlanClickStartTime: [],
      // $comment时间范围
      daterangePlanEndTime: [],
      // $comment时间范围
      daterangePlanStartTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        name: null,
        status: null,
        accountType: null,
        dateBilling: null,
        toSendInfo: null,
        jcCarrierId: null,
        driverTemporary: null,
        vehicleheadTemporary: null,
        jcOrganizationId: null,
        carrierType: null,
        driverIphoneTemporary: null,
        planClickEndTime: null,
        planClickStartTime: null,
        planEndTime: null,
        planStartTime: null,
        jcDriverId: null,
        driver: null,
        driverIphone: null,
        vehicleHead: null,
        jcVehicleId: null,
        jcVehicleheadId: null,
        cost: null,
        rate: null,
        taxes: null,
        isOverdueCarrier: null,
        isAbnormail: null,
        number: null,
        volume: null,
        weight: null,
        rebubbleRatio: null,
        agent: null,
        printCount: null,
        arrivePay: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        dateBilling: [
          { required: true, message: "请选择计划时间", trigger: "change" }
        ],
        jcVehicleId: [
          { required: true, message: "请选择车型", trigger: "change" }
        ],
        carrierType: [
          { required: true, message: "请选择承运类型", trigger: "change" }
        ],
        vehicleHead: [
          { required: true, message: "请输入车牌号", trigger: "blur" }
        ],
        driver: [
          { required: true, message: "请输入司机", trigger: "blur" }
        ],
        driverIphone: [
          { required: true, message: "请输入司机电话", trigger: "blur" }
        ],
        accountType: [
          { required: true, message: "请选择结算方式", trigger: "change" }
        ],
        cost1: [
          { required: true, message: "请输入车费", trigger: "blur" }
        ]
      },
      carrierList: [],
      licenseList: [],
      driverList: [],
      vehicleTypes: [],
      defaultOrg: {}
    };
  },
  created() {
    this.defaultOrg = JSON.parse(this.$cache.local.get('org'))
    this.getAllCarrier();
    this.getAllVehicle();
    this.getList();
  },
  computed: {
    // 计算 cost
    cost() {
      const cost = this.form.cost1 + this.form.cost2 + this.form.cost3 + this.form.cost4;
      this.form.cost = cost;
      return cost;
    },
    taxes() {
      const taxes = (this.form.cost * this.form.rate).toFixed(2);
      this.form.taxes = taxes;
      return taxes;
    }
  },
  methods: {
    /** 查询提派单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      if (null != this.daterangeModifyTime && '' != this.daterangeModifyTime) {
        this.queryParams.params["beginModifyTime"] = this.daterangeModifyTime[0];
        this.queryParams.params["endModifyTime"] = this.daterangeModifyTime[1];
      }
      if (null != this.daterangeDateBilling && '' != this.daterangeDateBilling) {
        this.queryParams.params["beginDateBilling"] = this.daterangeDateBilling[0];
        this.queryParams.params["endDateBilling"] = this.daterangeDateBilling[1];
      }
      if (null != this.daterangePlanClickEndTime && '' != this.daterangePlanClickEndTime) {
        this.queryParams.params["beginPlanClickEndTime"] = this.daterangePlanClickEndTime[0];
        this.queryParams.params["endPlanClickEndTime"] = this.daterangePlanClickEndTime[1];
      }
      if (null != this.daterangePlanClickStartTime && '' != this.daterangePlanClickStartTime) {
        this.queryParams.params["beginPlanClickStartTime"] = this.daterangePlanClickStartTime[0];
        this.queryParams.params["endPlanClickStartTime"] = this.daterangePlanClickStartTime[1];
      }
      if (null != this.daterangePlanEndTime && '' != this.daterangePlanEndTime) {
        this.queryParams.params["beginPlanEndTime"] = this.daterangePlanEndTime[0];
        this.queryParams.params["endPlanEndTime"] = this.daterangePlanEndTime[1];
      }
      if (null != this.daterangePlanStartTime && '' != this.daterangePlanStartTime) {
        this.queryParams.params["beginPlanStartTime"] = this.daterangePlanStartTime[0];
        this.queryParams.params["endPlanStartTime"] = this.daterangePlanStartTime[1];
      }
      listDispatch(this.queryParams).then(response => {
        this.dispatchList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.abnormal = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        createName: null,
        createTime: null,
        description: null,
        modifyName: null,
        modifyTime: null,
        name: null,
        status: null,
        accountType: null,
        dateBilling: null,
        toSendInfo: null,
        jcCarrierId: null,
        driverTemporary: null,
        vehicleheadTemporary: null,
        jcOrganizationId: null,
        carrierType: null,
        driverIphoneTemporary: null,
        planClickEndTime: null,
        planClickStartTime: null,
        planEndTime: null,
        planStartTime: null,
        jcDriverId: null,
        driver: null,
        driverIphone: null,
        vehicleHead: null,
        jcVehicleId: null,
        jcVehicleheadId: null,
        cost: 0,
        cost1: 0,
        cost2: 0,
        cost3: 0,
        cost4: 0,
        rate: 0,
        taxes: 0,
        isOverdueCarrier: null,
        isAbnormail: null,
        number: null,
        volume: null,
        weight: null,
        rebubbleRatio: null,
        agent: null,
        printCount: null,
        arrivePay: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.daterangeModifyTime = [];
      this.daterangeDateBilling = [];
      this.daterangePlanClickEndTime = [];
      this.daterangePlanClickStartTime = [];
      this.daterangePlanEndTime = [];
      this.daterangePlanStartTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.codes = selection.map(item => item.code)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加提派单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDispatch(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改提派单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDispatch(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDispatch(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除提派单编号为"' + ids + '"的数据项？').then(function () {
        return delDispatch(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dispatch/dispatch/export', {
        ...this.queryParams
      }, `dispatch_${new Date().getTime()}.xlsx`)
    },
    getAllCarrier() {
      allListCarrier().then(response => {
        this.carrierList = response.data;
      });
    },
    getAllVehicle() {
      allListVehicle().then(response => {
        this.vehicleTypes = response.data;
      });
    },
    /** 车牌号搜索 */
    changeVehicle(val) {
      console.log('val' + val);
      this.licenseList = [];
      searchVehicleExistList(val).then(response => {
        this.licenseList = response.data;
      });
    },
    /** 车牌号选中 */
    handleLicenseSelect(val) {
      this.form.license = val;
      this.licenseList.forEach(item => {
        if (item.code === val) {
          this.form.jcVehicleHeadId = item.id;
          this.form.jcDriverId = item.jcDriverId;
          this.form.driver = item.driver;
          this.form.driverIphone = item.iphone;
        }
      });
    },
    /** 司机名称搜索 */
    queryDriverSearch(query, cb) {
      this.driverList = [];
      if (query && query !== "" && query.length >= 2) {
        searchListDriver(query).then(response => {
          // 将name 换为 value
          if (response.rows) {
            response.rows.forEach(item => {
              item.value = item.name;
            });
            cb(response.rows);
            this.driverList = response.rows;
          }
        });
      }
    },
    /** 司机名称选中 */
    handleDriverSelect(item) {
      this.form.jcDriverId = item.id;
      this.form.driver = item.name;
      this.form.driverIphone = item.phone;
    },
    handleAbnormal() {
      this.reset();
      const id = this.ids
      getDispatch(id).then(response => {
        if (response.data.status === 1) {
          this.$modal.msgError("未开始执行的提派单不能修改异常信息");
          return;
        }
        this.form = response.data;
        this.open = true;
        this.title = "修改提派单异常信息";
        this.abnormal = true;
      });
    },
    handleSaveAbnormal() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          dispatchSaveAbnormal(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.abnormal = false;
            this.getList();
          });
        }
      });
    },
    handleStartExe() {
      const ids = this.ids
      const codes = this.codes;
      this.$modal.confirm('是否确认开始执行提派单编号为"' + codes + '"的数据项？').then(function () {
        return startDispatch(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("开始执行成功");
      }).catch(() => {
      });
    },
    handleEndExe() {
      const ids = this.ids
      const codes = this.codes;
      this.$modal.confirm('是否确认结束执行提派单编号为"' + codes + '"的数据项？').then(function () {
        return startDispatch(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("结束执行成功");
      }).catch(() => {
      });
    }
  }
};
</script>
